const seq = require('../../../../db/seq');
const { string, integer, text } = require('../../../../db/types');
const { verification } = require('../../../../db/verification')

const model = {
    type: {
        type: integer,
        allowNull: false,
        default: 1102,
        comment: '菜单类型：1101为目录 1102为菜单 1103为功能（按钮）',
        verification: 'number',
    },
    label: {
        allowNull: false,
        comment: '目录/菜单/功能名称',
        type: string,
        verification: 'string',
    },
    name: {
        allowNull: true,
        comment: '前端标识(组件/路由名称)',
        type: string,
        verification: 'string',
    },
    parentId: {
        type: integer,
        allowNull: false,
        default: 0,
        comment: '父目录id',
        verification: 'number',
    },
    perm: {
        type: string,
        allowNull: true,
        comment: '功能标识',
        verification: 'string',
    },
    apiIds: {
        type: string,
        allowNull: true,
        comment: 'apis，主要是方便前端回显',
        verification: 'array',
        get() {
            return this.getDataValue('apiIds').split(',').filter(item => item != "");
        },
        set(value) {
            return this.setDataValue('apiIds', value.join(','))
        }
    },
    icon: {
        type: string,
        allowNull: true,
        comment: 'icon',
        verification: 'string',
    },
    hidden: {
        type: integer,
        allowNull: false,
        comment: '是否隐藏 1101隐藏 1102显示',
        verification: 'number',
    },
    sort: {
        type: integer,
        allowNull: false,
        default: 0,
        comment: '排序',
        verification: 'number',
    }
}

const verifiMenus = (data) => {
    return verification(data, model);
}

// 系统接口表
const Menus = seq.define('menus', model);

module.exports = {
    Menus,
    verifiMenus
};
